<?php
require('common/common.php');

$Input = new Input();
$username = $Input->get('username');
$passwd = $Input->get('passwd');
$return_url = $Input->get('return_url',Input::RAW,'index.php');
$fail = false;

if (isset($username)) {
    User::initialize(db_connect());
    if (User::login($username,$passwd)) {
        header("Location: $return_url");
        die();
    } else $fail = true;
}

?>
<!DOCTYPE html>
<HTML><head>
    <title>Login</title>
</head>
<body>
    <div id="header"></div><br>
    <div id="main"><?php
        if ($fail) { 
            echo "<h3>Username or password is incorrect</h3>\n";
        }
    ?>
    <h2>Login:</h2>
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'].'?return_url='.urlencode($return_url); ?>" >
        <label>Username: </label><input type="text" name="username" ><br>
        <label>Password: </label><input type="password" name="passwd" ><br>
        <input type="submit">
    </form>
    <p><a href="new_user.php">Create Account</a></p>
    <p><a href="reset_pw.php">Reset Password</a></p>
    </div>
</body></HTML>